package com.lmxdawn.api.admin.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lmxdawn.api.admin.annotation.AuthRuleAnnotation;
import com.lmxdawn.api.admin.req.ListPageRequest;
import com.lmxdawn.api.common.res.BaseResponse;
import com.lmxdawn.api.common.util.ResultVOUtils;
import com.lmxdawn.api.dnf.entity.ChargeConfig;
import com.lmxdawn.api.dnf.entity.UserBill;
import com.lmxdawn.api.dnf.service.IChargeConfigService;
import com.lmxdawn.api.dnf.service.IUserBillService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 代练服务 前端控制器
 * </p>
 *
 * @author huangyubin
 * @since 2024-07-05
 */
@RestController
@RequestMapping("/admin/dnf/chargeConfig")
public class ChargeConfigController {

    @Resource
    IChargeConfigService chargeConfigService;


    @GetMapping("/page")
    @AuthRuleAnnotation("admin/dnf/chargeConfig/page")
    public BaseResponse page(@Valid ListPageRequest pageRequest) {
        Page<ChargeConfig> page = Page.of(pageRequest.getPage(), pageRequest.getLimit());
        return ResultVOUtils.success(
                chargeConfigService.page(page,
                        Wrappers.<ChargeConfig>lambdaQuery().orderByDesc(ChargeConfig::getCreateTime)
                ));
    }

    @PostMapping("/save")
    @AuthRuleAnnotation("admin/dnf/chargeConfig/save")
    public BaseResponse save(@Valid @RequestBody ChargeConfig chargeConfig) {
        return ResultVOUtils.success(chargeConfigService.save(chargeConfig));
    }

    @PostMapping("/edit")
    @AuthRuleAnnotation("admin/dnf/chargeConfig/edit")
    public BaseResponse edit(@Valid @RequestBody ChargeConfig chargeConfig) {
        return ResultVOUtils.success(chargeConfigService.updateById(chargeConfig));
    }

    @PostMapping("/delete")
    @AuthRuleAnnotation("admin/dnf/chargeConfig/delete")
    public BaseResponse delete(@Valid @RequestBody ChargeConfig chargeConfig) {
        return ResultVOUtils.success(chargeConfigService.removeById(chargeConfig));
    }
}
